from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


# 自定义分页器
class CustomPageNumberPagination(PageNumberPagination):
    # page_query_param = ""
    page_size = 5  # 每页默认返回5条
    page_size_query_param = "size"  # 每页数据量
    max_page_size = 10  # 不能超过10条
    page_query_param = "page"  # 分页参数

    # 自定义分页返回数据
    def get_paginated_response(self, data):
        return Response({
            'count': self.page.paginator.count,
            'next': self.get_next_link(),
            'previous': self.get_previous_link(),
            'data': data,
        })